﻿--[[
   @brief    game download mgr wnd
   @author   maxyao
   @version  1.0
   @date     2019-04-26
--]]


download_mgr_control = 
{
    inited = false;
    
    init = function()
        base_utility.log("[download_mgr_control]download_mgr init");
        ierd_tgp.tpf_ui.Require("mainframe_tools_panel\\download_mgr\\view.lua");
        local tpfui = base_utility.get_component_adapter("ITpf_ui", "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:AddLuaListener(
            ierd_tgp.game_library.CLOSE_MAIN_WND, "download_mgr_control.close_wnd");
        comm_center.reg_service("i_service_dlmgr_show_close_btn", "download_mgr_control.show_close_btn");
        comm_center.reg_service("i_service_dlmgr_close", "download_mgr_control.on_click_close_btn");
    end;


    show = function(data)
        base_utility.log("[download_mgr_control]show");
        download_mgr_view:show(true);
        local table_param = data;
    end;

    -- 点击关闭按钮
    on_click_close_btn = function()
        base_utility.mainframe_report("download_mgr", "btn_click", "click_close_btn");
        download_mgr_view:close(); 
    end;

    -- 自动关闭
    close_wnd = function()
        base_utility.log("[download_mgr_control]close_wnd");
        download_mgr_view:close(); 
    end;

    -- 处理外部的关闭，（比如alt+f4）
    on_dialog_close = function(event_id, json_str)
        download_mgr_control.on_click_close_btn();
    end;


    on_show = function(uilib, ctrl_id)
        base_utility.log("[download_mgr_control] on_show download_mgr_view tpf");
        download_mgr_view:on_show(uilib, ctrl_id);
    end;


    on_web_browser_crash = function()
        base_utility.mainframe_report("download_mgr", "browser", "crash");
        download_mgr_control.close_wnd();
    end;

    show_close_btn = function(data)
        if data == nil or data.show == nil then
            return;
        end;
        download_mgr_view:show_close_btn(tonumber(data.show) == 1); 
    end;
};

download_mgr_control.init();

